import 'package:flutter/material.dart';
import 'package:flutterdemo/pages/AppbarDemo.dart';
import 'package:flutterdemo/pages/Aroute.dart';
import 'package:flutterdemo/pages/Search.dart';
import 'package:flutterdemo/pages/TabBarControl.dart';
import 'package:flutterdemo/pages/TextFiled.dart';
import 'package:flutterdemo/pages/TimeSelectPage.dart';
import 'package:flutterdemo/pages/User.dart';
import 'package:flutterdemo/pages/user/Login.dart';
import 'package:flutterdemo/pages/user/RegisterFirst.dart';
import 'package:flutterdemo/pages/user/RegisterSecond.dart';
import 'package:flutterdemo/pages/user/RegisterThird.dart';
import 'package:flutterdemo/row/row.dart';
import 'package:flutterdemo/stack/stack.dart';
import 'package:flutterdemo/tabs/tabs.dart';

import 'button/button.dart';
import 'card/card.dart';
import 'gridview/gridview.dart';
import 'layout/layout.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final routes = {
    // '/aroute': (context) => AroutePage(),
    '/aroute': (context, {arguments}) => AroutePage(arguments: arguments),
    '/loginroute': (context) => LoginPage(),
    '/registerfrist': (context) => RegisterFirstPage(),
    '/registersecond': (context) => RegisterSecondPage(),
    '/registerthird': (context) => RegisterThirdPage(),
    '/appBarDemo': (context) => AppBarDemoPage(),
    '/tabBarControl': (context) => TabBarControlPage(),
    '/user': (context) => UserPage(),
    '/textFiled': (context) => TextFiledPage(),
    '/timePage': (context) => TimeSelectPage(),
  };

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
        debugShowCheckedModeBanner: false,
        // initialRoute:  '/appBarDemo',
        title: "我是标题",
        home: Tabs(),
        onGenerateRoute: (RouteSettings settings) {
          // 统一处理
          final String? name = settings.name;
          final Function pageContentBuilder = this.routes[name] as Function;
          if (pageContentBuilder != null) {
            if (settings.arguments != null) {
              final Route route = MaterialPageRoute(
                  builder: (context) => pageContentBuilder(context,
                      arguments: settings.arguments));
              return route;
            } else {
              final Route route = MaterialPageRoute(
                  builder: (context) => pageContentBuilder(context));
              return route;
            }
          }
        });
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List list = [];

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        Column(
          children: this.list.map((value) {
            return Text(value);
          }).toList(),
        ),
        SizedBox(
          height: 20.0,
        ),
        RaisedButton(
          onPressed: () {
            setState(() {
              list.add("测试");
            });
          },
          child: Text("按钮"),
        )
      ],
    );
  }
}

/*
class HomeContent extends StatelessWidget {
  List list = [];

  HomeContent() {
    for (int i = 0; i < 30; i++) {
      this.list.add("我是条目$i");
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView.builder(
        itemCount: this.list.length,
        itemBuilder: (context, indext) {
          return ListTile(
            title: Text("大标题：" + this.list[indext]),
            subtitle: Text("我是二级标题:" + this.list[indext]),
          );
        });
  }
}*/
